﻿using Framework.Core.Io;
using Framework.Core.Process.Tasks;
using Rhino.Mocks;
using Xunit;

namespace Framework.Tests.Core.Process.Tasks
{
    public class ScTest
    {
        private readonly MockRepository mockRepository = new MockRepository();
        private readonly IProcessRunner processRunnerMock;

        public ScTest()
        {
            processRunnerMock = mockRepository.StrictMock<IProcessRunner>();
        }

        [Fact]
        public void Should_validate_sc_start_command()
        {
            var scStart = new Sc.ScStart("pouet");

            AssertName(scStart);
            Assert.Equal("start pouet", scStart.Arguments);
        }

        [Fact]
        public void Should_validate_sc_delete_command()
        {
            var scDelete = new Sc.ScDelete("toto");

            AssertName(scDelete);
            Assert.Equal(@"delete ""toto""", scDelete.Arguments);
        }

        [Fact]
        public void Should_validate_sc_create_command_without_user()
        {
            var scCreate = new Sc.ScCreate("sn", "dn", "bp", "a");

            Assert.Equal(@"create ""sn"" binPath= ""bp a"" displayname= ""dn"" start= auto", scCreate.Arguments);
            AssertName(scCreate);
        }

        [Fact]
        public void Should_validate_sc_create_command_with_user()
        {
            var scCreate = new Sc.ScCreate("sn", "dn", "bp", "a", "usr", "pwd");

            Assert.Equal(@"create ""sn"" binPath= ""bp a"" displayname= ""dn"" start= auto obj= ""usr"" password= ""pwd""", scCreate.Arguments);
            AssertName(scCreate);
        }

        private static void AssertName(ICommand command)
        {
            Assert.Equal("sc", command.Name);
            Assert.Equal(@"C:\Windows\System32\sc.exe", command.FileName);
            Assert.True(command.IsNative);
        }
    }
}